﻿using System;
using System.Collections;
using System.Data;
using CE.Database;

using System.Data.SqlClient;
using System.Data.Common;
/// <summary>
/// Summary description for CMIDB
/// </summary>
/// 
namespace CE.Promotion
{
    public class WorldCupFriendPromotionDB
    {
        public WorldCupFriendPromotionDB()
        {
        }

        public Int64 Insert(WorldCupFriendPromotion promotiondata)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocWorldCupFriendInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter                
            _sPara.Add("@WCFriendId", promotiondata.WCFriendId);
            _sPara.Add("@WCUserId", promotiondata.WCUserId);
            _sPara.Add("@FriendId", promotiondata.FriendId);
            _sPara.Add("@Name", promotiondata.Name);
            _sPara.Add("@Email", promotiondata.Email);
            _sPara.Add("@Mobile", promotiondata.Mobile);;
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public WorldCupFriendPromotion GetPromotion(Int64 WorldCupFriendId)
        {
            WorldCupFriendPromotion _promotion = null;
            MyDatabase _db = new MyDatabase();

            using (DataTable _dt = _db.GetDataTable("SELECT WCFriendId,WCUserId,FriendId,Name,Email,Mobile FROM tblWorldCupFriend WHERE [WCFriendId]=" + WorldCupFriendId.ToString()))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _promotion = new WorldCupFriendPromotion();
                    _promotion = FillDataRecord(_dt, 0);
                }
            }
            return _promotion;
        }

        private WorldCupFriendPromotion FillDataRecord(DataTable myDataTable, int RowId)
        {
            WorldCupFriendPromotion myPromotion = new WorldCupFriendPromotion();

            myPromotion.WCFriendId = Convert.ToInt16(myDataTable.Rows[RowId]["WCFriendId"].ToString());
            myPromotion.WCUserId = Convert.ToInt16(myDataTable.Rows[RowId]["WCUserId"].ToString());
            myPromotion.FriendId = Convert.ToInt16(myDataTable.Rows[RowId]["FriendId"].ToString());
            myPromotion.Name = myDataTable.Rows[RowId]["Name"].ToString();
            myPromotion.Email = myDataTable.Rows[RowId]["Email"].ToString();
            myPromotion.Mobile = myDataTable.Rows[RowId]["Mobile"].ToString();
            return myPromotion;
        }
    }
}
